package com.fin.zw.aiqas.controller;

import com.fin.zw.aiqas.annotation.CurrentUser;
import com.fin.zw.aiqas.model.request.ApprovalRequest;
import com.fin.zw.aiqas.model.response.ReconsiderResponse;
import com.fin.zw.aiqas.model.session.SessionModel;
import com.fin.zw.aiqas.service.ReconsiderationReviewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping("/reconsiderationReview")
@Api(value = "复核-复议-质检结果公用接口", description = "复核-复议-质检结果公用接口")
public class ReconsiderationReviewController {

    private final static Logger log = LoggerFactory.getLogger(ReconsiderationReviewController.class);

    @Autowired
    private ReconsiderationReviewService reconsiderationReviewService;

    /**
     * 根据任务ID查询质检结果详情明细
     */
    @GetMapping("/getApply")
    @ApiOperation(value = "根据质检结果详情ID查询质检复议详情", notes = "根据质检结果详情ID查询质检复议详情")
    public ResponseEntity<ReconsiderResponse> queryReconsideration(@RequestParam("inspectionId") Long inspectionId) {
        try {
            Long startTime = System.currentTimeMillis();
            ReconsiderResponse response = reconsiderationReviewService.queryReconsideration(inspectionId);
            Long endTime = System.currentTimeMillis();
            log.info("共耗时:{}",endTime - startTime);
            return ResponseEntity.ok().body(response);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            return ResponseEntity.badRequest().build();
        }
    }

    /**
     * 复核审批-复议审批操作
     */
    @PutMapping("/putApproval")
    @ApiOperation(value = "复核审批-复议审批操作", notes = "复核审批-复议审批操作")
    public ResponseEntity<Void> Approval(@RequestBody ApprovalRequest request, @ApiIgnore @CurrentUser SessionModel session) {
        reconsiderationReviewService.Approval(request, session);
        return ResponseEntity.ok().build();
    }


}
